package com.yc.dao;

import java.util.List;
import java.util.Map;

public class OrderDao {
	/**
	 * 管理员查询所有订单
	 * @return
	 */
	public List<Map<String, String>> FindAllOrder(){
		DBHelper db = new DBHelper();
		String sql = "select o_id, c_name, o_name, o_seat, o_starttime, o_endtime,  o_zwstatus, o_price  from tb_userorder order by o_starttime desc"; 
		return db.finds(sql);		
	}
		
	/**
	 * 查询某个用户的订单信息
	 */
	public List<Map<String, String>> findsAllOrder(String account){
		DBHelper db = new DBHelper();
		String sql = "select o_id, c_name, o_name, o_seat, o_starttime, o_endtime,  o_zwstatus, o_price  from tb_userorder where u_name = ? order by o_starttime desc"; 
		return db.finds(sql, account);		
	}
	/**
	 * 删除订单
	 * @param account
	 * @return
	 */
	public int delete(String tid) {
		DBHelper db = new DBHelper();
		String sql = "delete from  tb_userorder where o_id = ?";
		return db.update(sql, tid);
	}
	/**
	 * 修改票数
	 * @param seattype
	 * @param i
	 * @param cname
	 * @return
	 */
	public int updateNumberYZ(int i, String cname) {
		//update tb_price set p_yz = (p_yz + 1) where c_name = 'G5116';
		DBHelper db = new DBHelper();
		String sql = "update tb_price set p_yz = (p_yz + (?)) where c_name = ? ";
		return db.update(sql, i, cname);
	}
	public int updateNumberRW(int i, String cname) {
		//update tb_price set p_yz = (p_yz + 1) where c_name = 'G5116';
		DBHelper db = new DBHelper();
		String sql = "update tb_price set p_rw = (p_rw + (?)) where c_name = ? ";
		return db.update(sql, i, cname);
	}
	public int updateNumberYW(int i, String cname) {
		//update tb_price set p_yz = (p_yz + 1) where c_name = 'G5116';
		DBHelper db = new DBHelper();
		String sql = "update tb_price set p_yw = (p_yw + (?)) where c_name = ? ";
		return db.update(sql, i, cname);
	}
	public int updateNumberWZ(int i, String cname) {
		//update tb_price set p_yz = (p_yz + 1) where c_name = 'G5116';
		DBHelper db = new DBHelper();
		String sql = "update tb_price set p_wz = (p_wz + (?)) where c_name = ? ";
		return db.update(sql, i, cname);
	}
	/**
	 * 退票退钱
	 * @param i
	 * @param account
	 * @return
	 */
	public int updatebalance(int i,String account) {
		DBHelper db = new DBHelper();
		String sql = "update tb_user set u_balance = (u_balance + (?)) where u_name = ?";
		return db.update(sql, i, account );
	}
}